package dao;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import dto.RankingDTO;

import utiles.Conecta;

public class RankingDAO {

	public List getALLRanking() throws SQLException, IOException{
		
		Conecta connDao = new Conecta();
		Connection conn = connDao.ObtieneConexion();	
		List listRankingCC = new ArrayList();
		PreparedStatement stmt = null; 
        ResultSet rs=null; 
		try{
			String sql="Select POSICIONRANKING,RUTCORREDOR, NOMBRECORREDOR from "+ Conecta.schema +".CC_SALIDACORREDORES";    
            
            stmt=conn.prepareStatement(sql);  
            rs=stmt.executeQuery();
			
			
			while (rs.next()) {
				
				RankingDTO BuscaDTO = new RankingDTO();				
				BuscaDTO.setPosicionRanking(rs.getString(1));
				BuscaDTO.setRutCorredor(rs.getString(2));
				BuscaDTO.setNombreCorredor(rs.getString(3));
				
				System.out.println(rs.getString(1));
				System.out.println(rs.getString(2));
				System.out.println(rs.getString(3));
				
				listRankingCC.add(BuscaDTO);				
			}
			rs.close();
			stmt.close();
		} catch (SQLException ex) {  
			
			System.out.println(ex.getMessage());
		} finally {
			
			connDao.desconecta(conn);
		}	
	return listRankingCC;
}
	public static void main(String[] args) {
	
		RankingDAO carga = new RankingDAO();
		try {
			carga.getALLRanking();
		} catch (SQLException e) {		
			
			
			e.printStackTrace();
		} catch (IOException e) {
		
			e.printStackTrace();
		}
	}
}
